package com.ruoyi.yipaiju.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ApiResult;
import com.ruoyi.yipaiju.domain.DiscountHouseSigningorder;
import com.ruoyi.yipaiju.domain.ForeclosedHouseSigningorder;
import com.ruoyi.yipaiju.service.IDiscountHouseSigningorderService;
import com.ruoyi.yipaiju.service.IForeclosedHouseSigningorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/financial/manager")
public class FinancialManagerController extends BaseController {

    @Autowired
    private IForeclosedHouseSigningorderService foreclosedHouseSigningorderService;
    @Autowired
    private IDiscountHouseSigningorderService discountHouseSigningorderService;

    /**
     * 优选签约审核 财务经理
     * @param id
     * @param foreclosedHouseSigningorder
     * @return
     */
    @PostMapping("/houses/foreclosed/signing/orders/{id}")
    public ApiResult housesForeclosedSigningOrdersInfo(@PathVariable("id") Long id, @RequestBody ForeclosedHouseSigningorder foreclosedHouseSigningorder) {
        ForeclosedHouseSigningorder foreclosedHouseSigningorder1 = foreclosedHouseSigningorderService.selectForeclosedHouseSigningorderById(id);
        if (foreclosedHouseSigningorder.getFinancialManagerVertifyStatus().intValue() == 3){
            foreclosedHouseSigningorder1.setSubmitStatus(0);
        }
        foreclosedHouseSigningorder1.setFinancialManagerVertifyStatus(foreclosedHouseSigningorder.getFinancialManagerVertifyStatus());
        foreclosedHouseSigningorder1.setRejectReason(foreclosedHouseSigningorder.getRejectReason());

        int result = foreclosedHouseSigningorderService.updateForeclosedHouseSigningorder(foreclosedHouseSigningorder1);
        if (result > 0) {
            return ApiResult.success(foreclosedHouseSigningorder1);
        }else {
            return ApiResult.error();
        }
    }

    /**
     * 折扣签约审核 财务经理
     * @param id
     * @param discountHouseSigningorder
     * @return
     */
    @PostMapping("/houses/discount/signing/orders/{id}")
    public ApiResult housesDiscountSigningOrdersInfo(@PathVariable("id") Long id, @RequestBody DiscountHouseSigningorder discountHouseSigningorder) {
        DiscountHouseSigningorder discountHouseSigningorder1 = discountHouseSigningorderService.selectDiscountHouseSigningorderById(id);
        if (discountHouseSigningorder.getFinancialManagerVertifyStatus().intValue() == 3){
            discountHouseSigningorder1.setSubmitStatus(0);
        }
        discountHouseSigningorder1.setFinancialManagerVertifyStatus(discountHouseSigningorder.getFinancialManagerVertifyStatus());
        discountHouseSigningorder1.setRejectReason(discountHouseSigningorder.getRejectReason());

        int result = discountHouseSigningorderService.updateDiscountHouseSigningorder(discountHouseSigningorder1);
        if (result > 0) {
            return ApiResult.success(discountHouseSigningorder1);
        }else {
            return ApiResult.error();
        }
    }

}
